package com.xxxx.server.controller;


import com.xxxx.server.pojo.*;
import com.xxxx.server.pojo.result.EmployeeResult;
import com.xxxx.server.service.IEmployeeService;
import com.xxxx.server.utils.ExcelUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-10-15
 */
@RestController
@RequestMapping("/employee/basic")
public class EmployeeController {

    @Autowired
    private IEmployeeService iEmployeeService;

    @ApiOperation("分页获取全部员工信息")
    @GetMapping("/")
    public EmployeeResult showAllEmployee(Integer currentPage, Integer size, Employee employee,String beginDateScope){
        return iEmployeeService.selectAllEmployee(currentPage,size,employee,beginDateScope);
    }

    @ApiOperation("添加员工")
    @PostMapping("/")
    public RespBean add(@RequestBody Employee emp){
        //System.out.println(emp);
        return iEmployeeService.add(emp);
    }

    @ApiOperation("修改员工")
    @PutMapping("/")
    public RespBean edit(@RequestBody Employee emp){
        //System.out.println(emp);
        return iEmployeeService.edit(emp);
    }

    @ApiOperation("获取最大工号")
    @GetMapping("maxWorkID")
    public RespBean maxWorkID(){
        return iEmployeeService.getMaxWorkID();
    }

    @ApiOperation("获取职位信息")
    @GetMapping("positions")
    public List<Position> positions(){
        return iEmployeeService.getPositions();
    }

    @ApiOperation("获取民族信息")
    @GetMapping("nations")
    public List<Nation> nations(){
        return iEmployeeService.getNations();
    }
    @ApiOperation("获取职称信息")
    @GetMapping("joblevels")
    public List<Joblevel> joblevels(){
        return iEmployeeService.getJoblevels();
    }
    @ApiOperation("获取政治面貌信息")
    @GetMapping("politicsstatus")
    public List<PoliticsStatus> politicsstatus(){
        return iEmployeeService.getPoliticsStatuss();
    }
    @ApiOperation("获取部门信息")
    @GetMapping("deps")
    public List<Department> deps(){
        return iEmployeeService.getDepartments();
    }

    @ApiOperation("删除员工")
    @DeleteMapping("{id}")
    public RespBean delete(@PathVariable Integer id){
        return iEmployeeService.delete(id);
    }


    @ApiOperation("导出数据")
    @GetMapping("export")
    public void exportData(HttpServletResponse response) throws IOException {
        iEmployeeService.exportData(response);
    }
    @ApiOperation("导入数据")
    @PostMapping("import")
    public void importData( MultipartFile file) throws IOException {

        List<Employee> list = ExcelUtils.readExcel("", Employee.class, file);
        iEmployeeService.saveBatch(list);
    }



}
